﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TeamOPSchoolCup.Domain.POCO;
using TeamOPSchoolCup.Domain.DAL;
using TeamOPSchoolCup.Domain.Services;

namespace TeamOPSchoolCup.Web.Controllers
{ 
    public class NSSFController : Controller
    {
        private EFDbContext db = new EFDbContext();

        //
        // GET: /NSSF/

        public ViewResult Index()
        {
            var nssfs = db.NSSFs.Include(n => n.Region).Include("NSSFReps.Member");
            return View(nssfs.ToList());
        }

        //
        // GET: /NSSF/Details/5

        public ViewResult Details(int id)
        {
            NSSF nssf = db.NSSFs.Find(id);
            return View(nssf);
        }

        //
        // GET: /NSSF/Create

        public ActionResult Create()
        {
            ViewBag.NSSFId = new SelectList(db.Regions, "RegionId", "Name");
            return View();
        } 

        //
        // POST: /NSSF/Create

        [HttpPost]
        public ActionResult Create(NSSF nssf)
        {
            if (ModelState.IsValid)
            {
                db.NSSFs.Add(nssf);
                db.SaveChanges();
                return RedirectToAction("Index");  
            }

            ViewBag.NSSFId = new SelectList(db.Regions, "RegionId", "Name", nssf.NSSFId);
            return View(nssf);
        }
        
        //
        // GET: /NSSF/Edit/5
 
        public ActionResult Edit(int id)
        {
            NSSF nssf = db.NSSFs.Find(id);
            ViewBag.NSSFId = new SelectList(db.Regions, "RegionId", "Name", nssf.NSSFId);
            return View(nssf);
        }

        //
        // POST: /NSSF/Edit/5

        [HttpPost]
        public ActionResult Edit(NSSF nssf)
        {
            if (ModelState.IsValid)
            {
                db.Entry(nssf).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.NSSFId = new SelectList(db.Regions, "RegionId", "Name", nssf.NSSFId);
            return View(nssf);
        }

        //
        // GET: /NSSF/Delete/5
 
        public ActionResult Delete(int id)
        {
            NSSF nssf = db.NSSFs.Find(id);
            return View(nssf);
        }

        //
        // POST: /NSSF/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {            
            NSSF nssf = db.NSSFs.Find(id);
            db.NSSFs.Remove(nssf);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}